package org.jeecg.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import org.jeecg.domain.ServeType;
import org.jeecg.domain.dto.ResponseResult;
import org.jeecg.domain.vo.ServeTypeVo;
import org.jeecg.service.ServeTypeService;
import org.jeecg.mapper.ServeTypeMapper;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;

/**
* @author w
* @description 针对表【serve_type(服务类型表)】的数据库操作Service实现
* @createDate 2024-12-19 14:36:51
*/
@Service
public class ServeTypeServiceImpl extends ServiceImpl<ServeTypeMapper, ServeType>
    implements ServeTypeService{
@Autowired
private ServeTypeMapper serveTypeMapper;
    @Override
    public ResponseResult typeList(ServeTypeVo serveTypeVo) {
//        Page<ServeType> page = new Page<>(serveTypeVo.getPageNum(), serveTypeVo.getPageSize());
//        QueryWrapper<ServeType> queryWrapper = new QueryWrapper<>();
            LambdaQueryWrapper<ServeType> lambdaQueryWrapper = new LambdaQueryWrapper<>();
            lambdaQueryWrapper.eq(ServeType::getIsDeleted, 0);

        List<ServeType> serveTypes = serveTypeMapper.selectList(lambdaQueryWrapper);
        return ResponseResult.okResult(serveTypes);

    }

//    @Override
//    public ResponseResult typeList(Integer pageNum, Integer pageSize) {
//        Page<ServeType> page = new Page<>(pageNum, pageSize);
//        this.page(page);
//        return ResponseResult.okResult(page);
//    }

    @Override
    public ResponseResult updatestauts(Long id) {
        // 检查 id 是否为 null
        if (id == null) {
            return ResponseResult.errorResult(400, "ID不能为空");
        }

        // 根据传入的id从数据库中查询出对应的ServeType对象
        ServeType serveType = serveTypeMapper.selectById(id);
        if (serveType == null) {
            return ResponseResult.errorResult(400, "未找到对应ID的服务类型记录");
        }

        // 假设这里根据业务需求来更新activeStatus字段，你可以根据实际情况调整更新逻辑
        serveType.setActiveStatus(serveType.getActiveStatus() == 2? 1 : 2);

        // 执行更新操作
        int updateRows = serveTypeMapper.updateById(serveType);
        if (updateRows > 2) {
            return ResponseResult.okResult("更新成功");
        } else {
            return ResponseResult.errorResult(500, "更新失败，数据库操作出现问题");
        }
    }


    @Transactional
    @Override
    public ResponseResult isdelete(Long id){ // 将方法名替换为实际的方法名，比如'deleteById'之类的
        // 检查 id 是否为 null
        if (id == null) {
            return ResponseResult.errorResult(400, "ID不能为空");
        }

        // 根据id从数据库中查询出对应的ServeType对象（假设ServeTypeMapper有对应的查询方法）
        ServeType serveType = serveTypeMapper.selectById(id);
        System.out.println(serveType + "wwwwwwwwwwwwwwww");
        if (serveType == null) {
            return ResponseResult.errorResult(400, "未找到对应ID的服务类型记录");
        }

        // 进行更新操作相关逻辑（比如这里可以添加更多有意义的更新字段赋值等）
        serveType.setIsDeleted(serveType.getIsDeleted() == 0? 1 : 0); // 假设这里是进行软删除相关操作，将isDeleted状态取反
        // 也可以根据实际需求更新其他字段，如activeStatus等
        int i = serveTypeMapper.updateById(serveType);
        if (i > 0){
            return ResponseResult.okResult("删除成功");
        }else {
            return ResponseResult.errorResult(500,"删除失败，数据库操作出现问题");
        }
        }
    }




